package com.lynx.core.servlet;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

import org.apache.commons.lang.StringUtils;

import com.lynx.core.type.Encoding;
import com.lynx.core.util.CONST;

public class MyHttpRequest extends HttpServletRequestWrapper {

	public MyHttpRequest(HttpServletRequest request) {
		super(request);
	}
	
	@Override
	public String getParameter(String name) {
		String value = super.getParameter(name);
		String temp = "";
		if (StringUtils.isNotBlank(value)&&StringUtils.isNotBlank(CONST.EncodingVal)) {
			try {
				temp = new String(value.getBytes(Encoding.iso_8859_1.getCode()),CONST.EncodingVal);
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}else{
			temp = value;
		}
		return temp;
	}
	
	@Override
	public String[] getParameterValues(String name){
		String[] tmp = null;
		String[] vals = super.getParameterValues(name);
		if(vals!=null&&vals.length>0){
			try {
				tmp = new String[vals.length];
				for(int i=0;i<vals.length;i++){
					if(StringUtils.isNotBlank(CONST.EncodingVal)){
						tmp[i] =  new String(vals[i].getBytes(Encoding.iso_8859_1.getCode()),CONST.EncodingVal);
					}else{
						tmp[i] =vals[i];
					}
				}
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		return tmp;
	}
	
	

}
